﻿Imports ControleMatricula.Negocio

Public Class FrmRelGeral
    Dim db As New DataClassesDataContext()

    Private Sub btnGerarRel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGerarRel.Click

        Dim ListRelGeral As List(Of SPRelGeralResult)
        ListRelGeral = db.SPRelGeral().ToList()

        Dim DSGeral As DataSet
        DSGeral = New DataSet()

        DSGeral.Tables.Add(New DataTable("SPRelGeral"))

        DSGeral.Tables(0).Columns.Add("Nome")
        DSGeral.Tables(0).Columns.Add("DEEspecifica")
        DSGeral.Tables(0).Columns.Add("Valor")
        DSGeral.Tables(0).Columns.Add("ValorTotalAluno")
        DSGeral.Tables(0).Columns.Add("DEPagamento")
        DSGeral.Tables(0).Columns.Add("Parcelas")

        If ListRelGeral.Count > 0 Then

            For x = 0 To ListRelGeral.Count - 1

                Dim row As DataRow = DSGeral.Tables(0).NewRow()

                row("Nome") = ListRelGeral(x).Nome
                row("DEEspecifica") = ListRelGeral(x).DEEspecifica
                row("Valor") = ListRelGeral(x).Valor
                row("ValorTotalAluno") = ListRelGeral(x).ValorTotalAluno
                row("DEPagamento") = ListRelGeral(x).DEPagamento
                row("Parcelas") = ListRelGeral(x).Parcelas

                DSGeral.Tables(0).Rows.Add(row)

            Next

        Else

            MsgBox("Não foi encontrado nenhum registro!", MsgBoxStyle.Information)
            Exit Sub

        End If

        DSGeral.AcceptChanges()

        Dim DS As New DataSet

        DS.Tables.Add(DSGeral.Tables(0).Copy)

        DS.AcceptChanges()

        Dim Geral As Geral
        Geral = New Geral()

        Geral.SetDataSource(DS)

        RelGeral.CrystalReportRelGeral.ReportSource = Geral
        RelGeral.CrystalReportRelGeral.RefreshReport()

        RelGeral.Show()

    End Sub

End Class